package main

func main() {

	//strsArray := []string{"a", "b", "c"}
	//str := "sssssss"

	//测试用例1   1,1,2,3,3
	l3 := ListNode{
		Val:  3,
		Next: nil,
	}
	l2 := ListNode{
		Val:  3,
		Next: &l3,
	}
	l1 := ListNode{
		Val:  2,
		Next: &l2,
	}
	l0 := ListNode{
		Val:  1,
		Next: &l1,
	}
	head := ListNode{
		Val:  1,
		Next: &l0,
	}

	resp := deleteDuplicates(&head)
	for resp != nil {
		println(resp.Val)
		resp = resp.Next
	}

}

//Definition for singly-linked list.
type ListNode struct {
	Val  int
	Next *ListNode
}

func deleteDuplicates(head *ListNode) *ListNode {
	if head == nil {
		return head
	}
	headNode := head
	workNode := headNode
	for workNode.Next != nil {
		if workNode.Val == workNode.Next.Val { //相邻节点相等
			workNode.Next = workNode.Next.Next //直接删除worknode的下一个结点。
		} else { //不等
			workNode = workNode.Next
		}
	}
	return headNode
}
